//
//  XDNavigationController.m
//  HengHuaSupervision
//
//  Created by XD-XY on 3/20/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "XDNavigationController.h"
#import "SumitViewController.h"

#import "XDHeader.h"
#import "XDTools.h"

#define btn_tag 32767

@interface XDNavigationController ()

@end

@implementation XDNavigationController
DEFINE_SINGLETON_FOR_CLASS(XDNavigationController);

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    if (IOS7){
        [[UINavigationBar appearance] setBackgroundImage:mNav_Bg_Img_Ios7 forBarMetrics:UIBarMetricsDefault];
    }else{
        [[UINavigationBar appearance] setBackgroundImage:mNav_Bg_Img forBarMetrics:UIBarMetricsDefault];
    }
    
  //  self.navigationBar.backItem.hidesBackButton = YES;
  //  self.navigationController.navigationBar.backItem.hidesBackButton =YES;
   

    //自定义标题栏
    self.titleLabel = [UILabel initLabel:mNav_TitleLabel_Frame textFont:mNav_Title_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentCenter];
    [self.navigationBar addSubview:_titleLabel];
    
    //自定义返回按钮
    self.backBtn = [UIButton initButton:CGRectMake(15,(mUI_Navigation_Bar_Height-mNav_Back_Img.size.height)/2.0f, mNav_Back_Img.size.width, mNav_Back_Img.size.height) btnImage:mNav_Back_Img btnTitle:nil titleColor:nil titleFont:nil];
    _backBtn.tag = btn_tag;
    [_backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationBar addSubview:_backBtn];
    
    //自定义头像
    self.userBtn = [UIButton initButton:CGRectMake(15,(mUI_Navigation_Bar_Height-mNav_Userhead_Img.size.height)/2.0f, mNav_Userhead_Img.size.width, mNav_Userhead_Img.size.height) btnImage:mNav_Userhead_Img btnTitle:nil titleColor:nil titleFont:nil];
    _userBtn.adjustsImageWhenHighlighted = NO;
    [self.navigationBar addSubview:_userBtn];
    
    //自定义用户名标签
    self.userLabel = [UILabel initLabel:CGRectMake(width_x(_userBtn)+18, 0,100, mUI_Navigation_Bar_Height) textFont:mNav_Username_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentLeft];
    [self.navigationBar addSubview:_userLabel];
    _userLabel.text = @"张丽丽";
    
    //自定义数据初始化按钮
    self.initlalizeBtn = [UIButton initButton:CGRectMake(1515/2.0f, (mUI_Navigation_Bar_Height-mNav_InitData_Normal_Img.size.height)/2.0f, mNav_InitData_Normal_Img.size.width, mNav_InitData_Normal_Img.size.height) btnNorImage:mNav_InitData_Normal_Img btnPressBtn:mNav_InitData_Highlight_Img btnTitle:nil titleColor:nil titleFont:nil];
    [_initlalizeBtn addTarget:self action:@selector(initlalizeData) forControlEvents:UIControlEventTouchDown];
    [self.navigationBar addSubview:_initlalizeBtn];
    
    //自定义数据初始化标签
    self.initlalizeLabel = [UILabel initLabel:CGRectMake(1613/2.0f,0,80, mUI_Navigation_Bar_Height) textFont:mNav_Username_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentLeft];
    [self.navigationBar addSubview:_initlalizeLabel];
    _initlalizeLabel.text = @"数据初始化";
    
    //自定义未提交按钮
    self.waitSubmitBtn = [UIButton initButton:CGRectMake(1791/2.0f,(mUI_Navigation_Bar_Height-mNav_Waitsumit_Highlight_Img.size.height)/2.0f,mNav_Waitsumit_Normal_Img.size.width, mNav_Waitsumit_Normal_Img.size.height) btnNorImage:mNav_Waitsumit_Normal_Img btnPressBtn:mNav_Waitsumit_Highlight_Img btnTitle:nil titleColor:nil titleFont:nil];
    [_waitSubmitBtn addTarget:self action:@selector(gotoSubmitViewController) forControlEvents:UIControlEventTouchDown];
    [self.navigationBar addSubview:_waitSubmitBtn];
    
    //自动以未提交标签
    self.waitSubmitLabel = [UILabel initLabel:CGRectMake(1886/2.0f, 0,80, mUI_Navigation_Bar_Height) textFont:mNav_Username_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentLeft];
    [self.navigationBar addSubview:_waitSubmitLabel];
    _waitSubmitLabel.text = @"本地提交";
}

//返回
-(void)backBtnClick:(UIButton *)sender
{
    if (sender.tag == btn_tag){
        [self popViewControllerAnimated:YES];
    }else{
        [self popToRootViewControllerAnimated:YES];
    }
}

//数据全部下载
-(void)initlalizeData
{

}

//进入待提交数据页面
-(void)gotoSubmitViewController
{
    SumitViewController * sumitVC = [[SumitViewController alloc] init];
    [self pushViewController:sumitVC animated:YES];
}

//控制隐藏返回按钮
-(void)setHiddenBackBtn:(BOOL)ishidden
{
    if (ishidden){
        _backBtn.hidden = YES;
        _userBtn.frame = CGRectMake(12,(mUI_Navigation_Bar_Height-mNav_Userhead_Img.size.height)/2.0f, mNav_Userhead_Img.size.width, mNav_Userhead_Img.size.height);
        _userLabel.frame = CGRectMake(width_x(_userBtn)+18, 0,100, mUI_Navigation_Bar_Height);
    }else{
        _backBtn.hidden =NO;
        _backBtn.frame = CGRectMake(12,(mUI_Navigation_Bar_Height-mNav_Back_Img.size.height)/2.0f, mNav_Back_Img.size.width, mNav_Back_Img.size.height);
        _userBtn.frame = CGRectMake(width_x(_backBtn)+22.5,(mUI_Navigation_Bar_Height-mNav_Userhead_Img.size.height)/2.0f, mNav_Userhead_Img.size.width, mNav_Userhead_Img.size.height);
        _userLabel.frame = CGRectMake(width_x(_userBtn)+7, 0,100, mUI_Navigation_Bar_Height);
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
